package com.cytech.cloudclinic.adapter.provide;

import android.view.View;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.provider.BaseNodeProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.bean.event.PrescriptionTagClick;

import org.greenrobot.eventbus.EventBus;

public class SecondNodeProvider extends BaseNodeProvider {
    public int currentPos = 0;

    @Override
    public int getItemViewType() {
        return 1;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_template_child;
    }

    @Override
    public void convert(BaseViewHolder helper, BaseNode data) {
        SecondNode entity = (SecondNode) data;
        TextView titleTv = helper.getView(R.id.tv_template_header);
        if(helper.getLayoutPosition()==currentPos){
            titleTv.setTextColor(ContextCompat.getColor(getContext(),R.color.colorPrimary));
        }else{
            titleTv.setTextColor(ContextCompat.getColor(getContext(),R.color.color_333333));
        }
        helper.setText(R.id.tv_template_header, entity.getTitle());

    }

    @Override
    public void onClick(BaseViewHolder helper, View view, BaseNode data, int position) {
        super.onClick(helper, view, data, position);
        currentPos = position;
        getAdapter().notifyDataSetChanged();
        SecondNode node = (SecondNode) data;
        EventBus.getDefault().post(new PrescriptionTagClick(node.getPrescription_id(),node.getTitle(),node.prescription_type));
    }
}
